<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2020/7/23
 * Time: 16:01
 */

namespace app\admin\controller\user;


use app\common\controller\AdminController;
use think\app;

class Comment extends AdminController
{
    public function __construct(App $app)
    {
        parent::__construct($app);
        $this->model = app('app\common\model\media\Comment');
        $this->topicmodel = app('app\common\model\user\Topic');
        $this->order = 'status asc,create_time asc';
    }

    public function get_where($arr = []){
        $array[]=['status','<>',2];
        if(isset($arr['title']) && !empty($arr['title'])){
            $ids = $this->topicmodel->where('title','like','%'.$arr['title'].'%')->column('id');
            $array[] = ['topic_id','in',$ids];
        }
        return $array;
    }

    public function get_with(){
        return ['user','topic'];
    }

    public function action(){

        $param= $this->request->param();

        try{
            $row = $this->model->where('id',$param['id'])->find();
            $row->save($param);

        }catch (\Exception $exception){
            return json(['code'=>1,'msg'=>$exception->getMessage()]);
        }
        return json(['code'=>0,'msg'=>'操作成功']);
    }
}